package colab.gui;



import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;

import colab.persistencia.LoginDAO;


import com.jgoodies.forms.factories.DefaultComponentFactory;
import java.awt.Font;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import java.awt.Toolkit;

public class TelaLogin extends JFrame {

	private JPanel contentPane;
	private JTextField textCpf;
	private JTextField textSenha;

	/**
	 * Launch the application.
	 */

	/**
	 * Create the frame.
	 */
	public TelaLogin() {
		setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\workspace\\CO-LAB\\src\\colab\\gui\\imagens\\COLAB-001.PNG"));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 564, 453);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textCpf = new JTextField();
		textCpf.setBounds(360, 26, 110, 20);
		contentPane.add(textCpf);
		textCpf.setColumns(10);
		
		textSenha = new JTextField();
		textSenha.setBounds(360, 57, 110, 20);
		contentPane.add(textSenha);
		textSenha.setColumns(10);
		
		
		JButton btnEntrar = new JButton("Entrar");
		btnEntrar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				final int cpf = Integer.parseInt(textCpf.getText());
				final String senha = textSenha.getText();
				
				try {
					LoginDAO.validarLogin(cpf, senha);
					dispose();
				} catch (SQLException e1) {
					
					e1.printStackTrace();
				}
			}
		});
		btnEntrar.setBounds(360, 88, 110, 23);
		contentPane.add(btnEntrar);
		
		JLabel lblLogin = DefaultComponentFactory.getInstance().createLabel("Login");
		lblLogin.setHorizontalAlignment(SwingConstants.RIGHT);
		lblLogin.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblLogin.setBounds(258, 26, 92, 17);
		contentPane.add(lblLogin);
		
		JLabel lblSenha = DefaultComponentFactory.getInstance().createLabel("Senha");
		lblSenha.setHorizontalAlignment(SwingConstants.RIGHT);
		lblSenha.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblSenha.setBounds(258, 58, 92, 14);
		contentPane.add(lblSenha);
		
		JLabel lblColab = DefaultComponentFactory.getInstance().createLabel("");
		lblColab.setIcon(new ImageIcon("C:\\workspace\\CO-LAB\\src\\colab\\gui\\imagens\\COLAB-001.PNG"));
		lblColab.setHorizontalAlignment(SwingConstants.CENTER);
		lblColab.setFont(new Font("Tahoma", Font.PLAIN, 19));
		lblColab.setBounds(0, -11, 548, 415);
		contentPane.add(lblColab);
		
		JButton btnNovoUsuario = new JButton("Cadastro de Alunos");
		btnNovoUsuario.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				new TelaCadastroUsuario().setVisible(true);
				dispose();
			}
		});
		btnNovoUsuario.setBounds(348, 122, 139, 20);
		contentPane.add(btnNovoUsuario);
	}
}
